package com.xxxx.vao.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxxx.vao.server.mapper.MenuRoleMapper;
import com.xxxx.vao.server.pojo.MenuRole;
import com.xxxx.vao.server.result.RespBean;
import com.xxxx.vao.server.service.IMenuRoleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiongl
 * @since 2021-04-20
 */
@Service
public class MenuRoleServiceImpl extends ServiceImpl<MenuRoleMapper, MenuRole> implements IMenuRoleService {

    @Override
    @Transactional
    public RespBean updateMenus(Integer rid, Integer[] mids) {
        baseMapper.delete(new QueryWrapper<MenuRole>().eq("rid",rid));
        if (mids == null || mids.length == 0){
            return RespBean.success("更新成功");
        }
        Integer result = baseMapper.insertRecord(rid,mids);
        if(mids.length == result){
            return RespBean.success("更新成功");
        }
        return RespBean.error("更新失败");
    }
}
